package com.zxy.paycenter.common.message.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.zxy.paycenter.common.constants.MessageResultConstant;
import com.zxy.paycenter.common.utils.DateUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * @author zxy
 */
@Data
@ApiModel(value = "响应基础model")
public class BaseResp<T> implements Serializable {
    /**
     * 请求的流水号
     */
    @ApiModelProperty(value = "流水号")
    @JsonProperty(value = "RequestId")
    private String requestId;
    /**
     * 状态 000000成功
     */
    @ApiModelProperty(value = "状态")
    @JsonProperty(value = "Status")
    private String status;
    /**
     * 消息
     */
    @ApiModelProperty(value = "消息")
    @JsonProperty(value = "Message")
    private String message;
    /**
     * 时间戳
     */
    @ApiModelProperty(value = "时间戳")
    @JsonProperty(value = "TimeStamp")
    private Long timeStamp;
    /**
     * 签名串
     */
    @ApiModelProperty(value = "签名串")
    @JsonProperty(value = "Hmac")
    private String hmac;
    /**
     * 响应对象
     */
    @ApiModelProperty(value = "响应对象")
    @JsonProperty(value = "Data")
    private T data;

    public BaseResp(String sts, String... message) {
        timeStamp = DateUtils.getNowTimeStamp();
        requestId = System.currentTimeMillis() + "";
        if (StringUtils.equals(sts, MessageResultConstant.SUCCESS)) {
            status = "000000";
            this.message = (message.length == 0 || StringUtils.isBlank(message[0])) ? "成功" : message[0];
        } else if (StringUtils.equals(sts, MessageResultConstant.SIGN_ERROR)) {
            status = "100000";
            this.message = (message.length == 0 || StringUtils.isBlank(message[0])) ? "签名错误" : message[0];
        } else if (StringUtils.equals(sts, MessageResultConstant.CHANNEL_ERROR)) {
            status = "200000";
            this.message = (message.length == 0 || StringUtils.isBlank(message[0])) ? "渠道编号错误" : message[0];
        } else if (StringUtils.equals(sts, MessageResultConstant.DATA_ERROR)) {
            status = "300000";
            this.message = (message.length == 0 || StringUtils.isBlank(message[0])) ? "数据错误" : message[0];
        } else if (StringUtils.equals(sts, MessageResultConstant.NULL_ERROR)) {
            status = "400000";
            this.message = (message.length == 0 || StringUtils.isBlank(message[0])) ? "请求字段包含空" : message[0];
        } else if (StringUtils.equals(sts, MessageResultConstant.ERROR)) {
            status = "999999";
            this.message = (message.length == 0 || StringUtils.isBlank(message[0])) ? "系统开小差了" : message[0];
        } else if (StringUtils.equals(sts, MessageResultConstant.VERSION_ERROR)) {
            status = "800000";
            this.message = (message.length == 0 || StringUtils.isBlank(message[0])) ? "非法的版本号" : message[0];
        } else if (StringUtils.equals(sts, MessageResultConstant.LOGIN_ERROR)) {
            status = "111111";
            this.message = (message.length == 0 || StringUtils.isBlank(message[0])) ? "登录失效" : message[0];
        }
    }
}
